home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / ge_cool.lha / GE_COOL2.1 / man / oldman3 / Bignum.3T < prev    next >
Text File  |  1992-06-26  |  14KB  |  464 lines

  1. .TH BIGNUM
  2. .SH NAME
  3. Bignum  Infinite precision integers
  4. .SH SYNOPSIS
  5. #include <cool/Bignum.h>
  6. .SH DESCRIPTION
  7. The 
  8.  Bignum 
  9. class implements near-infinite precision integers and arithmetic by 
  10. using a dynamic bit vector. A 
  11.  Bignum 
  12. object will grow in size as necessary to 
  13. hold its integer value. Implicit conversion to the system defined types 
  14.  short , 
  15.  int , 
  16.  long , 
  17.  float , 
  18. and 
  19.  double 
  20. is supported by overloaded operator member 
  21. functions. Addition and subtraction operators are performed by simple bitwise 
  22. addition and subtraction on 
  23.  unsigned short 
  24. boundaries with checks for carry 
  25. flag propagation. The multiplication,  division, and remainder operations 
  26. utilize the algorithms from Knuth's Volume 2 of \f2"The Art of Computer 
  27. Programming"\f1. However, despite the use of these algorithms and inline member 
  28. functions, arithmetic operations on 
  29.  Bignum 
  30. objects are considerably slower than 
  31. the built-in integer types that use hardware integer arithmetic capabilities.
  32. .PP
  33. The 
  34.  Bignum 
  35. class supports the parsing of character string representations of 
  36. all the literal number formats. The following table shows an example of a 
  37. character string representation on the left and a brief description of the 
  38. interpreted meaning on the right:
  39. .sp
  40. .nf
  41. .ta 2.5i
  42. \f2Character String Representation    Interpreted Meaning\f1
  43. \l'4.5i'
  44. .PP
  45. 1234    1234
  46. 12341    1234
  47. 1234L    1234
  48. 1234u    1234
  49. 1234U    1234
  50. 1234ul    1234
  51. 1234UL    1234
  52. 01234    1234 in octal (leading 0)
  53. 0x1234    1234 in hexadecimal (leading 0x)
  54. 0X1234    1234 in hexadecimal (leading 0X)
  55. 123.4    123 (value truncated)
  56. 1.234e2    123 (exponent expanded/truncated)
  57. 1.234e-5    0 (truncated value less than 1)
  58. \l'4.5i'
  59. .fi
  60. .PP
  61. The \f3Bignum\f1 class implements common arithmetic exception 
  62. handling and provides application support for detecting negative infinity, positive infinity, overflow, and underflow that may result from an operation. If one of these conditions is detected, an exception is raised. The programmer can provide an exception handler at runtime to take care of this problem. If no such handler is available, an error message is printed and program execution terminates. See Section 13 for more information on the cool exception handling mechanism.
  63. .SH Base Classes    
  64.  
  65. .SH Friend Classes    
  66. None
  67.  
  68. .SH Constructors
  69. .TP
  70.  inline Bignum ();
  71. Simple constructor to create a near-infinite precision integer object 
  72. initialized to zero.
  73. .TP
  74. \f3Bignum (const char* \f2str\f3);\f1
  75. Constructor to create a near-infinite precision integer object from the 
  76. character string representation 
  77.  str .
  78. .TP
  79. \f3Bignum (double \f2d\f3);\f1
  80. Constructor to create a near-infinite precision integer object from the double 
  81. value
  82.  d .
  83. .TP
  84. \f3Bignum (long \f2l\f3);\f1
  85. Constructor to create a near-infinite precision integer object from the long 
  86. integer value 
  87.  l .
  88. .TP
  89. \f3Bignum (const Bignum& \f2bn\f3);\f1
  90. Constructor to create a near-infinite precision integer object from 
  91.  bn .
  92. .SH Member Functions
  93. .TP
  94.  operator double ();
  95. Overloaded operator to provide implicit conversion between 
  96.  Bignum 
  97. objects and 
  98. the built-in 
  99.  double 
  100. type when appropriate.
  101. .TP
  102.  operator float ();
  103. Overloaded operator to provide implicit conversion between 
  104.  Bignum 
  105. objects and 
  106. the built-in 
  107.  float 
  108. type when appropriate.
  109. .TP
  110.  operator int ();
  111. Overloaded operator to provide implicit conversion between 
  112.  Bignum 
  113. objects and 
  114. the built-in 
  115.  int 
  116. type when appropriate.
  117. .TP
  118.  operator long ();
  119. Overloaded operator to provide implicit conversion between 
  120.  Bignum 
  121. objects and 
  122. the built-in 
  123.  long 
  124. type when appropriate.
  125. .TP
  126.  Bignum operator\- () const;
  127. Overloads the unary minus operator for the 
  128.  Bignum 
  129. class and returns a new 
  130. object whose value is the negated value of the object. If the operation results 
  131. in an arithmetic error of some type, the appropriate exception is raised.
  132. .TP
  133. \f3Bignum& operator= (const char* \f2str\f3);\f1
  134. Overloads the assignment operator for the 
  135.  Bignum 
  136. class and assigns the  integer 
  137. representation from the character string
  138.  str 
  139. to the infinite precision integer 
  140. object. A reference to the updated object is returned.
  141. .TP
  142. \f3Bignum& operator= (const \f3Bignum& \f2bn\f3);\f1
  143. Overloads the assignment operator for the 
  144.  Bignum 
  145. class and assigns 
  146.  bn 
  147. to the 
  148. infinite precision integer object. A reference to the updated object is 
  149. returned.
  150. .TP
  151.  inline Boolean operator! () const;
  152. Overloads the unary negation operator for the 
  153.  Bignum 
  154. class. A new 
  155.  Bignum 
  156. object 
  157. is returned as the result. If the operation results in an arithmetic error of 
  158. some type, the appropriate exception is raised.
  159. .TP
  160.  Bignum operator~ () const;
  161. Overloads the unary exclusive-or operator for the 
  162.  Bignum 
  163. class. A new 
  164.  Bignum 
  165. object is returned as the result. If the operation results in an arithmetic 
  166. error of some type, the appropriate exception is raised.
  167.  
  168. .TP
  169.  Bignum& operator++ ();
  170. Overloads the increment operator to provide an increment capability for the 
  171.  Bignum 
  172. class. A reference to the modified 
  173.  Bignum 
  174. object is returned as the 
  175. result. If the operation results in an arithmetic error of some type, the 
  176. appropriate exception is raised.
  177. .TP
  178.  Bignum& operator\-\^\- ();
  179. Overloads the decrement operator to provide a decrement capability for the 
  180.  Bignum 
  181. class. A reference to the modified 
  182.  Bignum 
  183. object is returned as the 
  184. result. If the operation results in an arithmetic error of some type, the 
  185. appropriate exception is raised.
  186. .TP
  187. \f3void operator+= (const Bignum&\f2 bn\f3);\f1
  188. Overloads the addition with assignment operator for the 
  189.  Bignum 
  190. class.  If the 
  191. operation results in an arithmetic error of some type, the appropriate 
  192. exception is raised.
  193. .TP
  194. \f3void operator\-= (const Bignum& \f2bn\f3);\f1
  195. Overloads the subtraction with assignment operator for the 
  196.  Bignum 
  197. class.  If 
  198. the operation results in an arithmetic error of some type, the appropriate 
  199. exception is raised.
  200. .TP
  201. \f3Bignum& operator*= (const Bignum& \f2bn\f3);\f1
  202. Overloads the multiplication with assignment operator for the 
  203.  Bignum 
  204. class. If 
  205. the operation results in an arithmetic error of some type, the appropriate 
  206. exception is raised.
  207. .TP
  208. \f3void operator/= (const Bignum& \f2bn\f3);\f1
  209. Overloads the division with assignment operator for the 
  210.  Bignum 
  211. class. If the 
  212. operation results in an arithmetic error of some type, the appropriate 
  213. exception is raised.
  214. .TP
  215. \f3void operator%= (const Bignum& \f2bn\f3);\f1
  216. Overloads the modulus with assignment operator for the 
  217.  Bignum 
  218. class. If the 
  219. operation results in an arithmetic error of some type, the appropriate 
  220. exception is raised.
  221. .TP
  222. \f3void operator&= (const Bignum& \f2bn\f3);\f1
  223. Overloads the logical AND with assignment operator for the 
  224.  Bignum 
  225. class. If the 
  226. operation results in an arithmetic error of some type, the appropriate 
  227. exception is raised.
  228. .TP
  229. \f3void operator^= (const Bignum& \f2bn\f3);\f1
  230. Overloads the exclusive-or with assignment operator for the 
  231.  Bignum 
  232. class. If 
  233. the operation results in an arithmetic error of some type, the appropriate 
  234. exception is raised.
  235. .TP
  236. \f3void operator|\^= (const Bignum& \f2bn\f3);\f1
  237. Overloads the logical OR with assignment operator for the
  238.  Bignum 
  239. class.  If the 
  240. operation results in an arithmetic error of some type, the appropriate 
  241. exception is raised.
  242. .TP
  243. \f3void operator>>= (const Bignum& \f2bn\f3);\f1
  244. Overloads the right shift with assignment operator for the 
  245.  Bignum 
  246. class. If the 
  247. operation results in an arithmetic error of some type, the appropriate 
  248. exception is raised.
  249. .TP
  250. \f3void operator<<= (const Bignum& \f2bn\f3);\f1
  251. Overloads the left shift with assignment operator for the 
  252.  Bignum 
  253. class. If the 
  254. operation results in an arithmetic error of some type, the appropriate 
  255. exception is raised.
  256. .TP
  257. \f3Boolean operator== (const Bignum& \f2bn\f3) const;\f1
  258. Overloads the equality operator for the 
  259.  Bignum 
  260. class. This function returns 
  261.  
  262.  TRUE 
  263. if the infinite precision integers have the same value; otherwise, this 
  264. function returns 
  265.  
  266.  FALSE .
  267. .TP
  268. \f3inline Boolean operator!= (const Bignum&\f2 bn\f3) const;\f1
  269. Overloads the inequality operator for the 
  270.  Bignum 
  271. class. This function returns 
  272.  
  273.  TRUE 
  274. if the infinite precision integers have different values; otherwise, this 
  275. function returns 
  276.  
  277.  FALSE .
  278.  
  279. .TP
  280. \f3Boolean operator< (const Bignum&\f2 bn\f3) const;\f1
  281. Overloads the less than operator for the 
  282.  Bignum 
  283. class and returns 
  284.  
  285.  TRUE 
  286. if the 
  287. object is less than the specified argument; otherwise, this function returns 
  288.  
  289.  FALSE .
  290. .TP
  291. \f3inline Boolean operator<= (const Bignum& \f2bn\f3) const;\f1
  292. Overloads the less than or equal operator for the 
  293.  Bignum 
  294. class. This function 
  295. returns 
  296.  
  297.  TRUE 
  298. if the object is less than or equal to the value of the specified 
  299. argument; otherwise, this function returns 
  300.  
  301.  FALSE .
  302. .TP
  303. \f3Boolean operator> (const Bignum& \f2bn\f3) const;\f1
  304. Overloads the greater than operator for the 
  305.  Bignum 
  306. class and returns 
  307.  
  308.  TRUE 
  309. if 
  310. the object is greater than the specified argument; otherwise, this function 
  311. returns 
  312.  
  313.  FALSE .
  314. .TP
  315. \f3inline Boolean operator>= (const Bignum& \f2bn\f3) const;\f1
  316. Overloads the greater than or equal operator for the 
  317.  Bignum 
  318. class. This 
  319. function returns 
  320.  
  321.  TRUE
  322. if the object is greater than or equal to the value of 
  323. the specified argument; otherwise, this function returns 
  324.  
  325.  FALSE .
  326. .TP
  327.  operator short ();
  328. Overloaded operator to provide implicit conversion between 
  329.  Bignum 
  330. objects and 
  331. the built-in 
  332.  short 
  333. type when appropriate.
  334. .TP
  335.  inline N_Status status () const;
  336. Returns the numerical exception state of the 
  337.  Bignum 
  338. object.
  339. .SH Friend Functions    
  340. .TP
  341. \f3friend Bignum operator+ (const Bignum& \f2bn1\f3, const\f3 Bignum& \f2bn2\f3);\f1
  342. Overloads the addition operator to provide addition for the 
  343.  Bignum 
  344. class. A new 
  345.  Bignum 
  346. object is returned as the result. If the operation results in an 
  347. arithmetic error of some type, the appropriate exception is raised.
  348. .TP
  349. \f3inline friend Bignum operator\- (const Bignum& \f2bn1\f3, const \f3Bignum& \f2bn2\f3);\f1
  350. Overloads the subtraction operator to provide subtraction for the 
  351.  Bignum 
  352. class. 
  353. A new 
  354.  Bignum 
  355. object is returned as the result. If the operation results in an 
  356. arithmetic error of some type, the appropriate exception is raised.
  357. .TP
  358. \f3friend Bignum operator* (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  359. Overloads the multiplication operator to provide multiplication for the 
  360.  Bignum 
  361. class. A new 
  362.  Bignum 
  363. object is returned as the result. If the operation results 
  364. in an arithmetic error of some type, the appropriate exception is raised.
  365. .TP
  366. \f3friend Bignum operator/ (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  367. Overloads the division operator for the 
  368.  Bignum 
  369. class. A new 
  370.  Bignum 
  371. object is 
  372. returned as the result. If the operation results in an arithmetic error of some 
  373. type, the appropriate exception is raised.
  374. .TP
  375. \f3friend Bignum operator% (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  376. Overloads the modulus operator for the 
  377.  Bignum 
  378. class. A new 
  379.  Bignum 
  380. object is 
  381. returned as the result. If the operation results in an arithmetic error of some 
  382. type, the appropriate exception is raised.
  383. .TP
  384. \f3friend Bignum operator& (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  385. Overloads the logical AND operator for the 
  386.  Bignum 
  387. class. A new 
  388.  Bignum 
  389. object is 
  390. returned as the result. If the operation results in an arithmetic error of some 
  391. type, the appropriate exception is raised.
  392. .TP
  393. \f3friend Bignum operator^ (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  394. Overloads the logical exclusive-or operator for the 
  395.  Bignum 
  396. class. A new 
  397.  Bignum 
  398. object is returned as the result. If the operation results in an arithmetic 
  399. error of some type, the appropriate exception is raised.
  400. .TP
  401. \f3friend Bignum operator| (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  402. Overloads the logical OR operator for the 
  403.  Bignum 
  404. class. A new 
  405.  Bignum 
  406. object is 
  407. returned as the result. If the operation results in an arithmetic error of some 
  408. type, the appropriate exception is raised.
  409. .TP
  410. \f3friend Bignum operator>> (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  411. Overloads the right shift operator for the 
  412.  Bignum 
  413. class. A new 
  414.  Bignum 
  415. object is 
  416. returned as the result. If the operation results in an arithmetic error of some 
  417. type, the appropriate exception is raised.
  418. .TP
  419. \f3friend Bignum operator<< (const Bignum& \f2bn1\f3, const Bignum& \f2bn2\f3);\f1
  420. Overloads the left shift operator for the 
  421.  Bignum 
  422. class. A new 
  423.  Bignum 
  424. object is 
  425. returned as the result. If the operation results in an arithmetic error of some 
  426. type, the appropriate exception is raised.
  427. .TP
  428. \f3friend ostream& operator<< (ostream& \f2os\f3, const Bignum&\f2 bn\f3);\f1
  429. Overloads the output operator for a reference to a 
  430.  Bignum 
  431. object to provide a 
  432. formatted output.
  433. .TP
  434. \f3inline friend ostream& operator<< (ostream& \f2os\f3, const Bignum* \f2bn\f3);\f1
  435. Overloads the output operator for a pointer to a 
  436.  Bignum 
  437. object to provide a 
  438. formatted output.
  439. .SH NOTE
  440. The 
  441.  Bignum 
  442. class requires that the built-in type 
  443.  long 
  444. is larger than the 
  445. built-in type 
  446.  short 
  447. and can accommodate the result of multiplying two \f3short\f1
  448. values. The maximum positive value that can be represented by the 
  449.  Bignum 
  450. class 
  451. is: \s82^(sizeof(unsigned long) * sizeof(unsigned short)) \-1.
  452. .SH COPYRIGHT
  453.  
  454. Copyright (C) 1991 Texas Instruments Incorporated.
  455.  
  456. Permission is granted to any individual or institution to use, copy, modify,
  457. and distribute this software, provided that this complete copyright and
  458. permission notice is maintained, intact, in all copies and supporting
  459. documentation.
  460.  
  461. Texas Instruments Incorporated provides this software "as is" without
  462. express or implied warranty.
  463.  
  464.